package StudyCode.summary.Basic.myarray;

import java.util.Arrays;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ArrayClone {
	public static void main(String[] args) {
		// 方法1
		int[] arrays1 = new int[]{1, 2, 3, 4};
		int[] arrays2 = arrays1;
		System.out.println("方法1");
		System.out.println(arrays1 == arrays2);
		System.out.println(Arrays.toString(arrays1));
		System.out.println(Arrays.toString(arrays2));

		// 方法2
		int[] arrays3 = new int[]{1, 2, 3, 4};
		int[] arrays4 = arrays3.clone();
		System.out.println("方法2");
		System.out.println(arrays3 == arrays4);
		System.out.println(Arrays.toString(arrays3));
		System.out.println(Arrays.toString(arrays4));

		// 方法3
		int[] arrays5 = new int[]{1, 2, 3, 4};
		int[] arrays6 = Arrays.copyOf(arrays5, arrays5.length);
		System.out.println("方法3");
		System.out.println(arrays5 == arrays6);
		System.out.println(Arrays.toString(arrays5));
		System.out.println(Arrays.toString(arrays6));

		// 方法4
		int[] arrays7 = new int[]{1, 2, 3, 4};
		int[] arrays8 = Arrays.copyOfRange(arrays7, 0, arrays7.length);
		System.out.println("方法4");
		System.out.println(arrays7 == arrays8);
		System.out.println(Arrays.toString(arrays7));
		System.out.println(Arrays.toString(arrays8));

		// 方法5
		int[] arrays9 = new int[]{1, 2, 3, 4};
		int[] arrays10 = new int[arrays9.length];
		System.out.println("方法5");
		System.arraycopy(arrays9, 0, arrays10, 0, arrays9.length);
		System.out.println(arrays9 == arrays10);
		System.out.println(Arrays.toString(arrays9));
		System.out.println(Arrays.toString(arrays10));
	}
}
